﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Cashier.utils;

namespace Cashier.help
{
    public partial class SuggestForm : Form
    {
        private int sendcount = 0;

        public SuggestForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 发送邮件
        /// </summary>
        private void SendMail()
        {
            try
            {
                if (sendcount > 3)
                {
                    MessageBox.Show("感谢您提供的反溃建议！");
                }
                else
                {
                    String title = "天美收银软件建议反溃";
                    String body = textBox1.Text.Trim();
                    if (String.IsNullOrEmpty(body) || body.Length < 5)
                    {
                        MessageBox.Show("不能少于5个字符！");
                        return;
                    }
                    bool b = MailUtil.Send(title, body);
                    if (b)
                    {
                        sendcount++;
                        MessageBox.Show("感谢您提供的反溃建议！");
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                LogsUtil.Record(ex);
            }
        }

        /// <summary>
        /// 按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_send_Click(object sender, EventArgs e)
        {
            this.SendMail();
        }

        /// <summary>
        /// 重写键盘事件
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="keyData"></param>
        /// <returns></returns>
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            bool b = base.ProcessCmdKey(ref msg, keyData);
            switch (keyData)
            {
                case Keys.Escape:
                    this.Close();
                    break;
            }
            return b;
        }
    }
}
